<div class="content" v-loading="btnloading">
    <el-form :model="secretkeyruleForm" :rules="secretkeyrules" ref="fsecretkeyruleForm" label-width="120px" label-suffix="：">
        <el-form-item label="{lang apiurl}" prop="apiurl">
            <el-input class="maxWidth" v-model.trim="secretkeyruleForm.apiurl"></el-input>
            <el-text type="info" class="tipTxt" size="small" style="margin-bottom: 0">{lang apiurl_tips}</el-text>
        </el-form-item>

        <el-form-item label="{lang APIKEY}" prop="apikey">
            <el-input class="maxWidth" v-model.trim="secretkeyruleForm.apikey"></el-input>
            <el-text type="info" class="tipTxt" size="small" style="margin-bottom: 0">{lang apikey_tips}</el-text>
        </el-form-item>
        <el-form-item label="{lang chatModel}'">

            <el-select v-model="secretkeyruleForm.chatModel">

                <el-option v-for="item2 in models" :key="item2" :label="item2" :value="item2"></el-option>
            </el-select>
            <el-text type="info" class="tipTxt" size="small" style="margin-bottom: 0">{lang chatModel_tip}</el-text>
        </el-form-item>
        <el-form-item label="{lang status}">
            <el-switch
                v-model="secretkeyruleForm.status"
                active-text="{lang enable}"
                inactive-text="{lang close}"
                :active-value="1"
                :inactive-value="0"
            ></el-switch>
            <el-text type="info" class="tipTxt" size="small" style="margin-bottom: 0">{lang status_tip}</el-text>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="secretkeySubmit">{lang save}</el-button>
        </el-form-item>
    </el-form>
</div>
<script>
    let secretkeyMixin = {
        data() {
			return {
				secretkeyruleForm: {
					apiurl:"$setting['apiurl']",
					apikey:"$setting['apikey']",
                    chatModel:"$setting['chatModel']",
					status:$setting['status']
				},
				secretkeyrules: {
					apiurl: [
						{ required: true, message: '{lang forcesecques_cannot_empty}', trigger: 'blur' }
					]


				},
			}
		},
        methods: {
			secretkeySubmit(){
				var self = this;
				self.$refs.fsecretkeyruleForm.validate(async function(valid){
					if (valid) {
						var params = {
							'settingsumbit':true,
							'formhash':'{FORMHASH}',
							'apiurl':self.secretkeyruleForm.apiurl,
							'apikey':self.secretkeyruleForm.apikey,
							'chatModel':self.secretkeyruleForm.chatModel,
							'status':self.secretkeyruleForm.status,
						};
						
						self.btnloading = true;
						const {data: res} = await axios.post('{MOD_URL}&op=setting',params);
						if(res.success){
							 self.$message({
							 	message: '{lang save_success}',
							 	type: 'success'
							 });
							window.location.reload();
						}else{
							self.btnloading = false;
							self.$message.error(res.msg || '{lang submit_error}');
						}
				    
					} else {
						self.$message.error('{lang verify_fail}');
						self.btnloading = false;
						return false;
					}
				});
			}
		},
    }
</script>